package com.liang.reflectdemo3;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException {

//        method1();
//        method2();

//        method3();

//        method4();
//        method5();

//        method6();

    }

    public static void method6() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class aClass = Class.forName("com.liang.reflectdemo3.Student");
        Method function4 = aClass.getDeclaredMethod("function4", String.class);
        function4.setAccessible(true);
        Object reuslt = function4.invoke(aClass.newInstance(), "aaa");
        System.out.println(reuslt);
    }

    public static void method5() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class aClass = Class.forName("com.liang.reflectdemo3.Student");

        Method function3 = aClass.getMethod("function3", String.class);
        Object zhangsan = function3.invoke(aClass.newInstance(), "zhangsan");
        System.out.println(zhangsan);
    }

    public static void method4() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class aClass = Class.forName("com.liang.reflectdemo3.Student");

        Method function2 = aClass.getMethod("function2", String.class);
        function2.invoke(aClass.newInstance(), "zhangsna");
    }

    public static void method3() throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class aClass = Class.forName("com.liang.reflectdemo3.Student");

        Object o = aClass.newInstance();

        Method function1 = aClass.getMethod("function1");
        function1.invoke(o);
    }

    public static void method2() throws ClassNotFoundException {
        Class aClass = Class.forName("com.liang.reflectdemo3.Student");

        Method[] methods = aClass.getDeclaredMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
    }

    public static void method1() throws ClassNotFoundException {
        Class aClass = Class.forName("com.liang.reflectdemo3.Student");

        Method[] methods = aClass.getMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
    }
}
